package com.luoqiz.demo.userManage.controller;

import java.util.Date;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.luoqiz.demo.userManage.model.SysUser;
import com.luoqiz.demo.userManage.service.UserService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

@RestController
@RequestMapping("/userController")
@Api(value = "user控制器", description = "user控制器")
public class UserController {

	@Autowired
	private UserService userService;

	@ApiOperation(value = "获取用户测试接口", notes = "注意事项说明")
	@GetMapping("/getUserTest/{uId}")
	public SysUser getUserTest(@PathVariable String uId) {
		SysUser sysUser = new SysUser();
		sysUser.setBirthday(new Date());
		sysUser.setuId(uId);
		return sysUser;
	}
	
	@ApiOperation(value = "获取用户测试接口", notes = "注意事项说明")
	@GetMapping("/getUser/{id}")
	public SysUser getUser(@PathVariable int id) {
		SysUser sysUser = userService.querySysUser(id);
		return sysUser;
	}


	@ApiIgnore // 忽略此接口
	@GetMapping("/devToolTest/{uId}")
	public SysUser devToolTest(@PathVariable String uId) {
		SysUser sysUser = new SysUser();
		sysUser.setBirthday(new Date());
		sysUser.setuId(uId);
		return sysUser;
	}

	@ApiOperation(value = "添加用户测试接口", notes = "注意事项说明")
	@PostMapping("/addUserTest")
	public SysUser addUserTest(SysUser sysUser) {
		sysUser.setBirthday(new Date());
		return sysUser;
	}

	@ApiOperation(value = "添加用户", notes = "注意事项说明")
	@PostMapping("/addUser")
	public SysUser addUser(SysUser sysUser) {
		sysUser.setuId(UUID.randomUUID().toString());
		sysUser.setBirthday(new Date());
		int i = userService.saveSysUser(sysUser);
		if (i != 0) {
			return sysUser;
		}
		return null;
	}
}
